package com.bingbaihanji.hibernate.config;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

public class ThreadPID extends ClassicConverter {

    /**
     * The convert method is responsible for extracting data from the event and
     * storing it for later use by the write method.
     *
     * @param event 当需要显示线程ID的时候，返回当前调用线程的ID
     */
    @Override
    public String convert(ILoggingEvent event) {
        return String.valueOf(getPid());
    }

    public String getPid() {
        try {
            long pid1 = ProcessHandle.current().pid();
            return String.valueOf(pid1);
        } catch (Throwable ex) {
            return null;
        }
    }
}